import { ElNotification } from "element-plus"
export const checkApprover = (node) => {
    switch (node.assignedType) {
        case 1:
            if (node.nodeUserList.length == 0) {
                ElNotification({
                    title: '验证错误',
                    message: '指定成员不能为空',
                    type: 'warning',
                })
                return false
            }
            break;
        case 3:
            if (node.nodeUserList.length == 0) {
                ElNotification({
                    title: '验证错误',
                    message: '角色不能为空',
                    type: 'warning',
                })
                return false
            }
            break;
        case 8:
            if (node.formUserId == '') {
                ElNotification({
                    title: '验证错误',
                    message: '表单部门不能为空',
                    type: 'warning',
                })
                return false
            }
            break;
        case 9:
            if (node.nodeUserList.length == 0) {
                ElNotification({
                    title: '验证错误',
                    message: '指定部门不能为空',
                    type: 'warning',
                })
                return false
            }
            break;
    }
    if (node.refuse.handler === 'TO_NODE' && node.refuse.nodeId == '') {
        ElNotification({
            title: '验证错误',
            message: '驳回节点不能为空',
            type: 'warning',
        })
        return false
    }
    if (node.nobody.handler == 'TO_USER' && node.nobody.assignedUser.length == 0) {
        ElNotification({
            title: '验证错误',
            message: '指定人员不能为空',
            type: 'warning',
        })
        return false
    }
}
export const checkBranch = (node) => {
    let nodeError = false
    for (var i = 0; i < node.conditionNodes.length; i++) {
        let conditionNode = node.conditionNodes[i];
        conditionNode.error = false;
        let conditionList = conditionNode.conditionList;
        if (i != node.conditionNodes.length - 1) {
            var error = conditionList.length == 0;
            for (var it of conditionList) {
                error = it.conditionList.length == 0;
                for (var ite of it.conditionList) {
                    if(ite.keyType=="expression"){
                        if(check(ite.comments)|| check(ite.expression)){
                            error = true;
                            nodeError = true
                        }
                    }
                else{
                    if (check(ite.key) || check(ite.expression) || check(ite.value)) {
                        error = true;
                        nodeError = true
                    }
                }

                }
            }
            conditionNode.error = error;
        }
    }
    if(nodeError){
        ElNotification({
            title: '验证错误',
            message: '条件设置不完整',
            type: 'warning',
        })
        return false
    }
}
export const check = (s) => {
    if (s === undefined || s === null || ((typeof s) === 'string' && s.trim().length == 0)) {
        return true;
    }
    return false;
}